.align 3
.globl my_test_data
my_test_data:
	.dword 0x12345678abcdabcd

.global load_store_test
load_store_test:
	li t0, 0x80200000

	lb t1, (t0)
	lb t1, 4(t0)
	lb t1, -4(t0)
	ld t1, (t0)
	lb t1, 4(t0)

	lui t0, 0x80200
	lui t1, 0x40200

	la t0, my_test_data
	lla t1, my_test_data

	ret

# while(i < 5)
#	i++
.global bne_test
bne_test:
	li x5, 0
	li x6, 5
loop:
	addi x5, x5, 1
	bne x5, x6, loop

	ret

# add rd, rs1, rs2
.global add_test
add_test:
	li t0, 1
	li t1, 5
	add a0, t0, t1

	ret


# sub rd, rs1, rs2
.global sub_test
sub_test:
	li t0, -1
	li t1, -2
	sub t2, t0, t1

	ret

# exe5-2
# register int a, b, c, d, e;
# b = 1;
# c = 2;
# e = 3;
# a = b + c;
# d = a - e;
#
.global exe5_2_test
exe5_2_test:
	li t0, 1
	li t1, 2
	li t2, 3
	add t3, t0, t1
	sub t4, t3, t2

	ret

# addi rd, rs1, imm
# -2048 <= imm <=2047
.global addi_test
addi_test:
	li t0, 2
	addi t1, t0, -1

	ret

# lui rd, imm
.global lui_test
lui_test:
	lui	t0, 0x12345 	# t0 = 0x12345 << 12
	addi t0, t0, 0x678	# t0 = t0 + 0x678

	ret

# li rd, imm
.global li_test
li_test:
	# imm is in the range of [-2048, +2047]
	li t1, 0x80
	addi t1, x0, 0x80

	# imm is not in the range of [-2048, +2047]
	# and the most-significant-bit of "lower-12" is 0
	li t0, 0x12345001

	lui t0, 0x12345
	addi t0, t0, 0x001

	# imm is NOT in the range of [-2,048, +2,047]
	# and the most-significant-bit of "lower-12" is 1
	li t0, 0x12345fff

	lui t0, 0x12346
	addi t0, t0, -1

	ret

# la rd, address
.global la_test
la_test:
	la t0, test2
test2:
	li t1, 0x88

	ret

# and rd, rs1, rs2
.global and_test
and_test:
	li t0, 0x10		# t0 = b00010000
	li t1, 0x11		# t1 = b00010001
	and t2, t0, t1

	ret

# andi rd, rs1, imm
.global andi_test
andi_test:
	li t0, 0x10
	andi t2, t0, 0x11

	ret

# or rd, rs1, rs2
.global or_test
or_test:
	li t0, 0x10
	li t1, 0x11
	or t2, t0, t1

	ret

# ori rd, rs1, imm
.global ori_test
ori_test:
	li t0, 0x10
	ori t2, t0, 0x11

	ret

.global memcpy_test
memcpy_test:
	li t0, 0x80200000
	li t1, 0x80210000
	addi t2, t0, 32

1:
	ld a0, (t0)
	sd a0, (t1)
	addi t0, t0, 8
	addi t1, t1, 8
	bltu t0, t2, 1b

	ret


.global branch_test
branch_test:
	addi sp, sp, -8
	sd ra, (sp)

	li a0, 1
	li a1, 2
	call add_test
	nop

	ld ra, (sp)
	addi sp, sp, 8
	ret
